<?php
/*
 *  This file is part of Urd.
 *
 *  Urd is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 3 of the License, or
 *  (at your option) any later version.
 *  Urd is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program. See the file "COPYING". If it does not
 *  exist, see <http://www.gnu.org/licenses/>.
 *
 * $LastChangedDate: 2008-06-22 23:11:25 +0200 (Sun, 22 Jun 2008) $
 * $Rev: 1212 $
 * $Author: styck $
 * $Id: install.3.inc.php 1212 2008-06-22 21:11:25Z styck $
 */

// This is an include-only file:
if (!defined('ORIGINAL_PAGE')) die('This file cannot be accessed directly.');

// Check for database settings: ask account info

// Were these values entered before? If so, we remember:
$dbtype = isset($_SESSION['dbtype']) ? $_SESSION['dbtype'] : '';
$dbhost = isset($_SESSION['dbhost']) ? $_SESSION['dbhost'] : 'localhost';
$dbport = isset($_SESSION['dbport']) ? $_SESSION['dbport'] : '';
$dbname = isset($_SESSION['dbname']) ? $_SESSION['dbname'] : 'urddb';
$dbuser = isset($_SESSION['dbuser']) ? $_SESSION['dbuser'] : 'urd_user';
$dbpass = isset($_SESSION['dbpass']) ? $_SESSION['dbpass'] : '';
$dbruser = isset($_SESSION['dbruser']) ? $_SESSION['dbruser'] : '';
$dbrpass = isset($_SESSION['dbrpass']) ? $_SESSION['dbrpass'] : '';
$dbclear = isset($_SESSION['dbclear']) ? $_SESSION['dbclear'] : '';

// If this is an upgrade, we have a dbconfig.php... use these values instead:
@include('dbconfig.php');
if (isset($config['databasetype'])) {
	$dbtype = $config['databasetype'];
        $dbname = $config['database'];
        $dbuser = $config['db_user'];
        $dbpass = $config['db_password'];
        $dbhost = $config['db_hostname'];
}

$dbclear ? $dbclear = 'CHECKED' : $dbclear = '';
if ($dbhost == '') $dbhost = 'localhost';

$OUT .= '<tr><td colspan="2" class="install1">Database settings</td></tr>' . "\n";

$dbs = array();
   /* array (
	array ('mysql', 'MySQL'),
	array ('mysqli', 'MySQL Improved'),
	array ('mysqlt','MySQL with transactions'),
	array ('postgres7','Postgres 7'),
	array ('postgres8','Postgres 8')
	array ('postgres65','Postgres 6.4'),
	array ('sqlite','SQLite'),
	array ('',''),
);*/

if (extension_loaded('mysql')) {
    $dbs[] = array ('mysql', 'MySQL');
    $dbs[] = array ('mysqlt', 'MySQL with transactions');
}
if (extension_loaded('mysqli'))
    $dbs[] = array ('mysqli', 'MySQL Improved');

if (extension_loaded('pgsql')) {
    $dbs[] = array ('postgres7', 'Postgres 7');
    $dbs[] = array ('postgres8', 'Postgres 8');
}

if ($dbs == array()) {
    $OUT .= '<tr><td class="install2">No database driver installed (try sudo apt-get install php5-mysql)</td>';
	$OUT .= '<tr colspan="2"><td><a onclick="LoadPage(3);">'.$refreshpic.'</a></td></tr>';
} else {
$OUT .= <<<SELECTDB
<tr><td class="install2">Select your database:</td><td class="install3">
<select name="dbtype">
SELECTDB;
foreach($dbs as $l) {
	$OUT .= '<option ' . (($l[0] == $dbtype) ? 'selected="selected"' : '') . " value=\"{$l[0]}\">{$l[1]}</option>\n";
} 

$OUT .= <<<SELECTDB2
</select></td></tr>
<tr><td class="install2">Database hostname:</td><td class="install3">
<input type="text" name="dbhost" value="$dbhost"></td></tr>
<tr><td class="install2">Database port number (blank for default):</td><td class="install3">
<input type="text" name="dbport" value="$dbport"></td></tr>
<tr><td class="install2">Database name:</td><td class="install3">
<input type="text" name="dbname" value="$dbname"></td></tr>
<tr><td class="install2">Database username:</td><td class="install3">
<input type="text" name="dbuser" value="$dbuser"></td></tr>
<tr><td class="install2">Database password:</td><td class="install3">
<input type="password" name="dbpass" value="$dbpass"></td></tr>
<tr><td colspan="2"></td></tr>
<tr><td colspan="2"><b>Only</b> enter this if you use MySQL or Postgres and want URD to create the database and the useraccount:</td></tr>
<tr><td class="install2">Database root username:</td><td class="install3">
<input type=text name="dbruser" value="$dbruser"></td></tr>
<tr><td class="install2">Database root password:</td><td class="install3">
<input type="password" name="dbrpass" value="$dbrpass"></td></tr>
<tr><td class="install2">Delete existing database &amp; user (needed for example in case you overwrite an existing URD installation - normally not needed)?</td><td class="install3">
<input type="checkbox" name="dbclear" $dbclear></td></tr>

SELECTDB2;
$OUT .= '<tr colspan=2><td><a onclick="LoadPage(4);">'.$continuepic.'</a></td></tr>';
}
?>
